package com.example.studyproject.thread;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author kw
 * @program study-project
 * @description
 * @create 2024 - 09 - 30 13:02
 **/
@Configuration
public class ThreadPoolConfig {

    //    @Bean
//    public ThreadPoolExecutor threadPoolExecutor() {
//        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
//        taskExecutor.setCorePoolSize(10);
//        taskExecutor.setMaxPoolSize(20);
//        taskExecutor.setQueueCapacity(30);
//        taskExecutor.setThreadFactory(new CustomizableThreadFactory());
//        taskExecutor.setRejectedExecutionHandler(new BlockPolicy());
//        return taskExecutor.getThreadPoolExecutor();
//    }
    @Bean
    public ThreadPoolExecutor threadPoolExecutor() {
        return new ThreadPoolExecutor(10, 20,
                30L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000), new ThreadPoolExecutor.CallerRunsPolicy());
    }
}
